home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / ultra250.zip / UW_TUT5.C < prev    next >
Text File  |  1992-11-02  |  11KB  |  255 lines

  1. /****************************************************************************/
  2. /* UW_TUT5.C                                                                */
  3. /*                                                                          */
  4. /* NOTE: THIS FILE IS PUBLIC DOMAIN AND MAY BE MODIFIED AND USED AT WILL    */
  5. /*                                                                          */
  6. /* Now we get serious and add a data structure and entry fields to          */
  7. /* collect information from the user.                                       */
  8. /* We add quite a bit of code but it is really quite straightforward.  The  */
  9. /* bulk of the code is repetive, gathering data for similar data fields.    */
  10. /*   Notice that we add a function to display a customer.  We simply pass   */
  11. /* a pointer to desired customer and a pointer to the window in which to    */
  12. /* display the customer's information.                                      */
  13. /*   We use the function wn_gets_ll (low-level) for maximum flexibility.    */
  14. /* Refer to the function reference for details of this function.  Once the  */
  15. /* basic parameters are understood, it is quite easy to use.                */
  16. /*                                                                          */
  17. /*                                                         Dr. Boyd Gafford */
  18. /*                                                         Kevin Huck       */
  19. /*                                                         EnQue Software   */
  20. /*                                                         09/11/92         */
  21. /****************************************************************************/
  22. #include <time.h>
  23. #include <ctype.h>
  24. #include "uw.h"                           /* include the necessary headers  */
  25.  
  26. #define MAX_CUST 100
  27.  
  28. typedef struct cust
  29. {
  30.   int status;
  31.   int cust_no;
  32.   char business[34];
  33.   char name[34];
  34.   char addr[34];
  35.   char city[34];
  36.   char state[4];
  37.   char zip[10];
  38.   char phone[16];
  39.   char fax[16];
  40.   char date[10];
  41.   char memo[34];
  42.   char unused[26];                                /* round out to 256 bytes */
  43. } CUST;
  44.  
  45. /*----------------------- global window variables --------------------------*/
  46. WINDOW  Desk_wn, Window1;
  47. CUST    Customers[MAX_CUST];
  48.  
  49. /*-------------------------------- prototypes ------------------------------*/
  50. int disp_time(void);
  51. void disp_cust(CUST *cp, WINDOW *wnp);
  52.  
  53. /*********/
  54. /* ~main */
  55. /*       ********************************************************************/
  56. /*  Demonstrate data entry capability...                                    */
  57. /****************************************************************************/
  58. int main()
  59. {
  60.   int cust = 0, end_flag = 0;
  61.   WINDOW *wnp;
  62.   CUST *cp;
  63.   
  64.   wnp = &Window1;                         /* set local window pointer       */
  65.   init_video(80, 25);                     /* init video for 80 x 25 screen  */
  66.   init_clock(0x3333);                     /* init clock irq at 91 tics/sec  */
  67.  
  68.   wn_create(0, 0, V_cols-1, V_rows-1, NO_BDR, WN_NORMAL, &Desk_wn);
  69.   link_window(&Desk_wn);
  70.  
  71.   set_idle_func(disp_time);               /* set background clock function  */
  72.  
  73.   wn_create(5, 5, 75, 20, SLD_BDR, WN_POPUP, wnp);
  74.   wn_color(YELLOW, BLUE, wnp);            /* change the window colors       */
  75.   wn_bdr_color(WHITE, BLUE, wnp);         /* change the border's colors     */
  76.   link_window(wnp);
  77.  
  78.   /*------------- initialize first customer as EnQue Software --------------*/
  79.   cp = &Customers[0];
  80.   strcpy(cp->business, "EnQue Software"); 
  81.   strcpy(cp->name, "Kevin Huck & Boyd Gafford");  
  82.   strcpy(cp->addr, "Rt. 1 Box 116C"); 
  83.   strcpy(cp->city, "Pleasant Hill");  
  84.   strcpy(cp->state, "MO");  
  85.   strcpy(cp->zip, "64080"); 
  86.   strcpy(cp->phone, "(816) 987-2515");  
  87.   strcpy(cp->fax, "(816) 987-2515");       
  88.   strcpy(cp->date, "09/11/92");      
  89.   strcpy(cp->memo, "BBS 816-358-8990"); 
  90.   while(!end_flag)
  91.   {
  92.     cp = &Customers[cust];
  93.     mv_cs(1,1, wnp);
  94.     wn_printf(wnp, "Customer:%3d", cust+1);
  95.     wn_plst(CENTERED, 2,
  96.     "Press <Esc> to exit program", &Desk_wn);
  97.     wn_plst(CENTERED, 3, "Use cursor keypad to select customer", &Desk_wn);
  98.     disp_cust(cp, wnp);
  99.     wait_event();
  100.     switch(Event.key)
  101.     {
  102.       case KEY_ESC: end_flag = 1; break;
  103.       case KEY_HOME:
  104.         cust = 0;
  105.         break; 
  106.       case KEY_END:
  107.         cust = MAX_CUST-1;
  108.         break; 
  109.       case KEY_DN: 
  110.         if( cust < MAX_CUST-1 )
  111.           cust++;
  112.         break;
  113.       case KEY_UP: 
  114.         if( cust > 0 )
  115.           cust--;
  116.         break;
  117.       case KEY_PGUP: 
  118.         if( cust >= 10 )
  119.           cust -= 10;
  120.         else
  121.           cust = 0;
  122.         break;
  123.       case KEY_PGDN: 
  124.         if( cust < MAX_CUST-11 )
  125.           cust += 10;
  126.         else
  127.           cust = MAX_CUST-1;
  128.         break;
  129.       case 'b': case 'B':                         /* get new business name  */
  130.         mv_cs( 11, 3, wnp);
  131.         wn_gets_ll(cp->business, "________________________________",
  132.                                  "********************************",
  133.           swap_nibbles(wnp->att), G_UP_FST_CHAR2 | G_STRIP_END, 32, wnp);
  134.         break;
  135.       case 'n': case 'N':                         /* get new contact name   */
  136.         mv_cs( 11, 4, wnp);
  137.         wn_gets_ll(cp->name, "________________________________",
  138.                              "********************************",
  139.           swap_nibbles(wnp->att), G_UP_FST_CHAR2 | G_STRIP_END, 32, wnp);
  140.         break;
  141.       case 'a': case 'A':                         /* get new address        */
  142.         mv_cs( 11, 5, wnp);
  143.         wn_gets_ll(cp->addr, "________________________________",
  144.                              "********************************",
  145.           swap_nibbles(wnp->att), G_UP_FST_CHAR2 | G_STRIP_END, 32, wnp);
  146.         break;
  147.       case 'c': case 'C':                         /* get new city           */
  148.         mv_cs( 11, 6, wnp);
  149.         wn_gets_ll(cp->city, "________________________________",
  150.                              "********************************",
  151.           swap_nibbles(wnp->att), G_UP_FST_CHAR2 | G_STRIP_END, 32, wnp);
  152.         break;
  153.       case 's': case 'S':                         /* get new state          */
  154.         mv_cs( 51, 6, wnp);
  155.         wn_gets_ll(cp->state, "__", "UU",
  156.           swap_nibbles(wnp->att), G_EXIT_ON_FILL|G_STRIP_END, 2, wnp);
  157.         break;
  158.       case 'z': case 'Z':                         /* get new zip            */
  159.         mv_cs( 60, 6, wnp);
  160.         wn_gets_ll(cp->zip, "_____", "#####",
  161.           swap_nibbles(wnp->att), G_EXIT_ON_FILL|G_STRIP_END, 5, wnp);
  162.         break;
  163.       case 'p': case 'P':                         /* get new phone number   */
  164.         mv_cs( 11, 7, wnp);
  165.         wn_gets_ll(cp->phone, "(___)___-____", " ### ### ####",
  166.           swap_nibbles(wnp->att), G_EXIT_ON_FILL, 14, wnp);
  167.         break;                    
  168.       case 'f': case 'F':                         /* get new fax number     */
  169.         mv_cs( 11, 8, wnp);
  170.         wn_gets_ll(cp->fax, "(___)___-____", " ### ### ####",
  171.           swap_nibbles(wnp->att), G_EXIT_ON_FILL, 14, wnp);
  172.         break;
  173.       case 'd': case 'D':                         /* get new date           */
  174.         mv_cs( 11, 9, wnp);
  175.         wn_gets_ll(cp->date, "__/__/__", "## ## ##", swap_nibbles(wnp->att),
  176.           G_EXIT_ON_FILL, 8, wnp);
  177.         break;
  178.       case 'm': case 'M':                         /* get new memo field     */
  179.         mv_cs( 11, 10, wnp);
  180.         wn_gets_ll(cp->memo, "________________________________",
  181.                              "********************************",
  182.           swap_nibbles(wnp->att), G_STRIP_END, 32, wnp);
  183.         break;
  184.  
  185.     }
  186.   }
  187.   unlink_window(wnp);                     /* remove the window from screen  */
  188.   wn_destroy(wnp);
  189.   set_idle_func(NULL);                    /* remove background function     */
  190.   unlink_window(&Desk_wn);                /* remove the window from screen  */
  191.   wn_destroy(&Desk_wn);
  192.   end_clock();
  193.   end_video();                            /* clean up before we exit        */
  194.   return(1);
  195. }
  196. /*** end of main ***/
  197.  
  198. /**************/
  199. /* ~disp_time */
  200. /*            ***************************************************************/
  201. /*  This routine is called in the background by wait_event and will display */
  202. /*  the time once per second.  Notice the use of the global variables       */
  203. /*  Uw_timers.  There is an array of four "countdown" timers that are user  */
  204. /*  accessible.  Each "timer tic" will decrement the counts by one, until   */
  205. /*  0 is reached.  By "reloading" the timer with "Tics_per_sec", we only    */
  206. /*  display the time of day once per second.  "Tics_per_sec" is set         */
  207. /*  by init_clock.                                                          */
  208. /****************************************************************************/
  209. int disp_time(void)
  210. {
  211.   time_t t;
  212.   if( !Uw_timers[0] )                           /* has one second passed?   */
  213.   {
  214.     Uw_timers[0] = Tics_per_sec;                /* if so, reload timer      */
  215.     t = time(NULL);                             /* get time                 */
  216.     mv_cs(55, V_rows-1, &Desk_wn);          /* move window cursor       */
  217.     wn_st_qty(ctime(&t), 24, &Desk_wn);     /* output 24 characters     */
  218.     return(1);
  219.   }
  220.   return(0);
  221. }
  222. /*** end of disp_time ***/
  223.  
  224. /**************/
  225. /* ~disp_cust */
  226. /*            ***************************************************************/
  227. /*  This routine displays a customer in the desired window...               */
  228. /****************************************************************************/
  229. void disp_cust(CUST *cp, WINDOW *wnp)
  230. {
  231.   int r = 3;
  232.  
  233.   mv_cs( 1, r++, wnp );
  234.   wn_printf( wnp, "Business: %-32s", cp->business);
  235.   mv_cs( 1, r++, wnp );
  236.   wn_printf( wnp, "Name    : %-32s", cp->name );
  237.   mv_cs( 1, r++, wnp );
  238.   wn_printf( wnp, "Address : %-32s", cp->addr );
  239.   mv_cs( 1, r++, wnp );
  240.   wn_printf( wnp, "City    : %-32s State: %2s  Zip: %5s",
  241.     cp->city, cp->state, cp->zip );
  242.   wn_cleol(wnp);                                    /* clear to end of line */
  243.   mv_cs( 1, r++, wnp );
  244.   wn_printf( wnp, "Phone   : %-16s", cp->phone );
  245.   mv_cs( 1, r++, wnp );
  246.   wn_printf( wnp, "Fax     : %-16s", cp->fax );
  247.   mv_cs( 1, r++, wnp );
  248.   wn_printf( wnp, "Date    : %-10s", cp->date );
  249.   mv_cs( 1, r++, wnp );
  250.   wn_printf( wnp, "Memo    : %-32s", cp->memo );
  251. }
  252. /*** end of disp_cust ***/
  253.  
  254. /*** END OF FILE ***/
  255.